<template>
    <div>
        <el-page-header @back="goBack"></el-page-header>
        <div>
            <span style="margin-left: 650px;font-size: 30px">收票登记</span>
            <el-divider content-position="right"></el-divider>
            <div style="width: 1300px">
                <span style="font-size:20px;color: red">基本信息</span>
                <el-form label-width="200px" :model="ivoiceReceiveInfo">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="售票登记编号:">
                                <el-input disabled placeholder="保存后自动生成"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="开票类型:">
                                <el-select style="width: 450px;" v-model="ivoiceReceiveInfo.openType" placeholder="开票类型">
                                    <el-option label="==无来源==" value=""></el-option>
                                    <el-option label="材料" value="材料"></el-option>
                                    <el-option label="劳务" value="劳务"></el-option>
                                    <el-option label="分包" value="分包"></el-option>
                                    <el-option label="租赁" value="租赁"></el-option>
                                    <el-option label="其他" value="其他"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="项目名称:" required>
                                <input type="hidden" v-model="ivoiceReceiveInfo.pid" />
                                <el-input v-model="ivoiceReceiveInfo.projectName" @focus="pid" clearable></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="关联合同:">
                                <input type="hidden" v-model="ivoiceReceiveInfo.cid" />
                                <el-input v-model="ivoiceReceiveInfo.cname" @focus="contractname" clearable></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="收款单位:">
                                <el-select style="width: 450px;" v-model="ivoiceReceiveInfo.incomeCompanyId" placeholder="收款单位">
                                    <el-option value=" " label="收款单位"></el-option>
                                    <el-option
                                            :key="receiveCompany.id"
                                            v-for="receiveCompany in receiveCompanys"
                                            :value="receiveCompany.id"
                                            :label="receiveCompany.receiveCompanyName"
                                    ></el-option>

                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="付款单位:" required>
                                <el-select style="width: 450px;" v-model="ivoiceReceiveInfo.payCompanyId">
                                    <el-option value=" " label="付款单位"></el-option>
                                    <el-option
                                            :key="openCompany.id"
                                            v-for="openCompany in openCompanys"
                                            :value="openCompany.id"
                                            :label="openCompany.openCompanyName"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发票类型:" required>
                                <el-select style="width: 450px;" v-model="ivoiceReceiveInfo.invoiceType" placeholder="发票类型">
                                    <el-option label="==请选择==" value=""></el-option>
                                    <el-option label="增值税专用发票" value="增值税专用发票"></el-option>
                                    <el-option label="普通发票" value="普通发票"></el-option>
                                    <el-option label="收据" value="收据"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发票号码:" required>
                                <el-input v-model="ivoiceReceiveInfo.invoiceNo"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="发票金额:" required>
                                <el-input type="number" v-model="ivoiceReceiveInfo.invoiceAmount"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额大写:" required>
                                <el-input v-model="ivoiceReceiveInfo.amountUpper"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="开户账号:">
                                <el-input v-model="ivoiceReceiveInfo.accountNum"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="地址、电话:" required>
                                <el-input v-model="ivoiceReceiveInfo.phoneAddress"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="纳税人识别号:">
                                <el-input v-model="ivoiceReceiveInfo.taxplayerNo"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="填报人:">
                                <el-input disabled="disabled" v-model="ivoiceReceiveInfo.editer"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="日期:">
                                <el-date-picker
                                        type="date"
                                        placeholder="选择日期"
                                        style="width: 450px;"
                                        value-format="yyyy-MM-dd"
                                        v-model="ivoiceReceiveInfo.openDate"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="开户银行：">
                                <el-select style="width: 450px;" v-model="ivoiceReceiveInfo.accountBank" placeholder="发票类型">
                                    <el-option label="==选择==" value=""></el-option>
                                    <el-option label="中国银行" value="中国银行"></el-option>
                                    <el-option label="招商银行" value="中国银行"></el-option>
                                    <el-option label="工商银行" value="工商银行"></el-option>
                                    <el-option label="农业银行" value="农业银行"></el-option>
                                    <el-option label="邮政银行" value="邮政银行"></el-option>
                                </el-select>                </el-form-item>
                        </el-col>
                    </el-row>
                    <input type="hidden" v-model="ivoiceReceiveInfo.attachIds"/>
                    <multi-file-upload
                            style="font-size:20px;color: red"
                            title="附件"
                            action="http://localhost/uploads"
                            :params="{folder: 'securitylog'}"
                            :headers="{token: token}"
                            :show-button="!checkRoute"
                            @uploadSuccess="handleUploadSuccess"
                            :parent-file-list="fileList"
                    ></multi-file-upload>
                    <el-form-item>
                        <el-button type="primary" style="margin-left: 1000px" @click="addspdj">确认提交</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <!--所属项目子组件-->
        <el-dialog :visible.sync="dialogVisible" width="50%">
            <project-info-list v-if="dialogVisible" @row="project"></project-info-list>
        </el-dialog>
        <!-- 合同子组件 -->
        <el-dialog  :visible.sync="dialogVisible4"  width="50%">
            <laber-contract v-if="dialogVisible4"  @row="LaberContract"></laber-contract>
        </el-dialog>
    </div>
</template>

<script>
    import {OpenCompanySeriver} from "../../../model/gsl/OpenCompanySeriver";
    const  open=OpenCompanySeriver.getInstance();
    import {ReceiveCompanySeriver} from "../../../model/gsl/ReceiveCompanySeriver";
    const  rece=ReceiveCompanySeriver.getInstance();
    import {InvoiceReceiveInfoSrvice} from "../../../model/gsl/InvoiceReceiveInfoSrvice";
    const  inv=InvoiceReceiveInfoSrvice.getInstance();
    import { DateUtil } from "../../../model/common/DateUtil";
    import ProjectInfoList from "../../common/projectInfo/ProjectInfoList";
    import LaberContract from '../../common/providerinfo/LaberContract';

    export default {
        components: { ProjectInfoList,LaberContract},
        name: "InvoiceReceiveInfolist",
        data() {
            return {
                openCompanys:[],
                receiveCompanys:[],
                dialogVisible: false, //隐藏子组件
                dialogVisible4:false,//隐藏子组件
                ivoiceReceiveInfo: {
                    openDate: DateUtil.today(),
                    editer:sessionStorage.getItem("realName")
                },
                fileList: [],
                projectId: "" //所属项目id
            };
        },
        methods: {
            getopenCompany(){
                open.list(null).then((re)=>{
                    this.openCompanys=re.data.data;
                })
            },
            getreceiveCompanys(){
                rece.list(null).then((re)=>{
                    this.receiveCompanys=re.data.data;
                })
            },
            //开启隐藏项目子组件
            pid() {
                this.dialogVisible = true;
            },
            //响应项目组件
            project(row) {
                this.ivoiceReceiveInfo.pid = row.id;
                this.ivoiceReceiveInfo.projectName = row.projectName;
                this.dialogVisible = false;
            },
            //开启合同名称组件
            contractname(){
                this.dialogVisible4 = true;
            },
            //响应合同组件
            LaberContract(row){
                this.ivoiceReceiveInfo.cname =row.contract_name;
                this.ivoiceReceiveInfo.cid =row.id
                this.dialogVisible4 = false;
            },
            //上传
            handleUploadSuccess(ids) {
                this.ivoiceReceiveInfo.attachIds=ids
            },
            //返回
            goBack() {
                history.back();
            },
            //添加售票登记信息
            addspdj() {
                if (this.ivoiceReceiveInfo.openType == "" || this.ivoiceReceiveInfo.openType == undefined) {
                    this.$message.error("开票类型不能为空");
                } else {
                    if (this.ivoiceReceiveInfo.pid == "" || this.ivoiceReceiveInfo.pid == undefined) {
                        this.$message.error("项目名称不能为空");
                    } else {
                        if (
                            this.ivoiceReceiveInfo.incomeCompanyId == "" ||
                            this.ivoiceReceiveInfo.incomeCompanyId == undefined
                        ) {
                            this.$message.error("收款单位不能为空");
                        } else {
                            if (
                                this.ivoiceReceiveInfo.payCompanyId == "" ||
                                this.ivoiceReceiveInfo.payCompanyId == undefined
                            ) {
                                this.$message.error("付款单位不能为空");
                            } else {
                                if (
                                    this.ivoiceReceiveInfo.invoiceType == "" ||
                                    this.ivoiceReceiveInfo.invoiceType == undefined
                                ) {
                                    this.$message.error("发票类型不能为空");
                                } else {
                                    if (
                                        this.ivoiceReceiveInfo.invoiceNo == "" ||
                                        this.ivoiceReceiveInfo.invoiceNo == undefined
                                    ) {
                                        this.$message.error("发票号码不能为空");
                                    } else {
                                        if (
                                            this.ivoiceReceiveInfo.invoiceAmount == "" ||
                                            this.ivoiceReceiveInfo.invoiceAmount == undefined
                                        ) {
                                            this.$message.error("发票金额不能为空");
                                        } else {
                                            this.ivoiceReceiveInfo.comment="审批中"
                                            inv.save(this.ivoiceReceiveInfo)
                                                .then((re) => {
                                                    if(re.data.data==1){
                                                        this.$message("添加成功！");
                                                        this.$router.push({ path: "/InvoiceReceiveInfolist" });
                                                        this.ivoiceReceiveInfo = {};
                                                    }else {
                                                        this.$message.error("添加失败！");

                                                    }

                                                });
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },

        created() {
            this.getopenCompany();
            this.getreceiveCompanys();
        },
        computed: {
            token: {
                get() {
                    return this.$store.state.token;
                }
            },
            checkRoute() {
                return Object.keys(this.$route.params).length != 0;
            }
        }
    };
</script>

<style>
</style>
